// $_FILEHEADER_BEGIN ***************************
// 版权声明:Timer
// Copyright © 2012 - Timer All Rights Reserved
// 文件名称: NavStatus.m
// 创建日期: 15/12/1
// 创 建 人: 甄鑫
// 文件说明: <#content#>
// $_FILEHEADER_END ******************************


#import "NavStatus.h"
#import "IQUIWindow+Hierarchy.h"
#import "AppDelegate.h"
#import "BaseTabBar.h"

@implementation NavStatus
{
    __weak AppDelegate * _appDelegate;
    __weak BaseTabBar  * _tabBar;
    
}
DEF_SINGLETON(NavStatus)
- (UIViewController *)getCurVC
{
    if (_appDelegate.loginWindow.isKeyWindow)
    {
        return _appDelegate.loginWindow.currentViewController;
    }
    UINavigationController * curTabVC = _tabBar.selectedViewController;
    UIViewController * _curVC = curTabVC.topViewController;
    ITLogSP(@"当前所在的VC:%@",NSStringFromClass([_curVC class]));
    return _curVC;
}

- (UIWindow *)getCurWindow
{
    if ([_appDelegate.loginWindow isKeyWindow])
    {
        return _appDelegate.loginWindow;
    }
    return _appDelegate.window;
}

- (void)setAppdelegate:(AppDelegate *)appDelegate
{
    if (appDelegate!= _appDelegate)
    {
        _appDelegate = appDelegate;
        _tabBar = (BaseTabBar *)_appDelegate.window.rootViewController;
    }
}

- (TABBAR_TYPE)getCurTabbarType
{
    return _tabBar.selectedIndex;
}

- (void)setCurTabBarType:(TABBAR_TYPE)type
{
    if(_tabBar)
    {
        _tabBar.selectedIndex = type;
    }
    [self setCurWindowType:WINDOW_TYPE_NORMAL];
    ITLogSP(@"当前所选择的TabBarType:%@",@(type));
}

- (void)setCurWindowType:(WINDOW_TYPE)type
{
    if (type == WINDOW_TYPE_LOGIN)
    {
        [_appDelegate.loginWindow makeKeyAndVisible];
    }
    else
    {
        [_appDelegate.window makeKeyAndVisible];
        [[NSNotificationCenter defaultCenter] postNotificationName:NOTI_LoginSuccess object:nil];
    }
}
@end
